#!/bin/bash

# 以下路径需要修改成自己的NDK目录
export NDK_ROOT=/Users/zx/Library/Android/sdk/ndk/26.1.10909125
export TOOLCHAIN=$NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64

echo "<<<<<<<<<<<<<基于NDK22b编译 FFmpeg >>>>>>>>>>>>>>"
 
#设置编译平台的相关参数
#armv7-a
#ARCH=arm
#CPU=armv7-a 

#armv8-a
ARCH=aarch64
CPU=armv8

API=21
OS=android
PLATFORM=aarch64-linux-android
PREFIX=$(pwd)/android/$CPU
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "

#指定输出路径
PREFIX=$(pwd)/android/arm
SYSROOT=$TOOLCHAIN/sysroot
CROSS_PREFIX=$TOOLCHAIN/bin/llvm-

#工具链的完整目录/Users/zx/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang
#CROSS_PREFIX=$TOOLCHAIN/bin/$PLATFORM-
ANDROID_CROSS_PREFIX=$TOOLCHAIN/bin/${PLATFORM}$API-
echo "交叉工具链 $ANDROID_CROSS_PREFIX"
echo "开始编译 $CPU"
#该脚本命令中不能插入注释，每行命令必须以 \ 结尾
./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-gpl \
--enable-neon \
--enable-hwaccels \
--enable-postproc \
--enable-jni \
--enable-small \
--enable-mediacodec \
--enable-decoder=h264_mediacodec \
--enable-ffmpeg \
--disable-static \
--disable-ffplay \
--disable-ffprobe \
--disable-ffplay \
--disable-avdevice \
--disable-debug \
--disable-static \
--disable-doc \
--disable-symver \
--cross-prefix=$CROSS_PREFIX \
--target-os=$OS \
--arch=$ARCH \
--cpu=$CPU \
--cc=${ANDROID_CROSS_PREFIX}clang \
--cxx=${ANDROID_CROSS_PREFIX}clang++ \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fPIC $OPTIMIZE_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \

make clean
#编译
make
#安装
make install
echo "编译完成 $CPU"
